package com.example.message.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.Message;
import reactor.core.publisher.Flux;

import java.util.function.Consumer;
import java.util.function.Function;

@Slf4j
@Configuration
public class RecConsumer {
//    @Bean
//    public Consumer<Message<BaseMessage>> consumer() {
//        return msg -> {
//            log.info(Thread.currentThread().getName() + " Consumer1 Receive New Messages: " + msg.getPayload().getMsg());
//        };
//    }

    @Bean
    public Function<String,String> consumer() {
        return String::toUpperCase;
    }

    @Bean
    public Consumer<String> broadcast() {
        return str -> {
            log.info("接收字符串---{}", str);
        };
    }

    @Bean
    public Consumer<Message<String>> delay() {
        return str -> {
            log.info("接收JSON---{}", str);
        };
    }

    @Bean
    public Consumer<Flux<Message<String>>> im() {
        return messageFlux -> messageFlux.subscribe(stringMessage -> System.out.println("Flux :" + stringMessage.getPayload()));
    }

}
